//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.controller;

import com.example.common.Result;
import com.example.entity.Admin;
import com.example.service.AdminService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import java.util.List;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/admin"})
public class AdminController {
    @Resource
    private AdminService adminService;

    public AdminController() {
    }

    @GetMapping({"/selectAll"})
    public Result selectAll(Admin admin) {
        List<Admin> list = this.adminService.selectAll(admin);
        return Result.success(list);
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Admin admin = this.adminService.selectById(id);
        return Result.success(admin);
    }

    @GetMapping({"/selectList"})
    public Result selectList(Admin admin) {
        List<Admin> list = this.adminService.selectList(admin);
        return Result.success(list);
    }

    @GetMapping({"/selectPage"})
    public Result selectPage(Admin admin, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Admin> pageInfo = this.adminService.selectPage(admin, pageNum, pageSize);
        return Result.success(pageInfo);
    }

    @PostMapping({"/add"})
    public Result add(@RequestBody Admin admin) {
        this.adminService.add(admin);
        return Result.success();
    }

    @PutMapping({"/updateById"})
    public Result updateById(@RequestBody Admin admin) {
        this.adminService.updateById(admin);
        return Result.success();
    }

    @DeleteMapping({"/deleteById/{id}"})
    public Result deleteById(@PathVariable Integer id) {
        this.adminService.deleteById(id);
        return Result.success();
    }

    @DeleteMapping({"/deleteBatch"})
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        this.adminService.deleteBatch(ids);
        return Result.success();
    }
}
